package com.mall.db.domain;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 
 * </p>
 *
 * @author LSM
 * @since 2021-09-22
 */
@Data
@EqualsAndHashCode(callSuper = false)
@TableName("t_goods")
public class Goods extends BaseEntity implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 商品id 我是
     */
    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;

    private String name;

    /**
     * 商品编号
     */
    private String number;

    public String getNumber() {
       if (number.equals("")||number.equals(null)){
           return System.currentTimeMillis()+"";
       }
       return number;
    }

    /**
     * 市场价格
     */
    private Integer marketPrice;


    /**
     * 商品图片
     */
    private String photo;
    @TableField(exist = false)
    private List<Integer> photos;

    public List<Integer> getPhotos() {
        if (photo!=null&&!photo.equals("")){
            return JSON.parseArray(photo,Integer.class);
        }
        List<Integer> list = new ArrayList<>();
        list.add(0);
        return list;
    }

    /**
     * 轮播图片
     */
    private String carouselPhoto;
    @TableField(exist = false)
    private List<Integer> carouselPhotos;

    public List<Integer> getCarouselPhotos() {
        if (carouselPhoto!=null&&!carouselPhoto.equals("")){
            return JSON.parseArray(carouselPhoto,Integer.class);
        }
        List<Integer> list = new ArrayList<>();
        list.add(0);
        return list;
    }

    /**
     * 商品单位(个/盒/瓶)
     */
    private String unit;

    /**
     * 关键字
     */
    private String keyword;
    @TableField(exist = false)
    private List<String> keywords;

    public List<String> getKeywords() {
        if (keyword!=null){
            return JSON.parseArray(keyword,String.class);
        }

        return keywords;

    }

    /**
     * 商品分类
     */
    private String categories;

    /**
     * 品牌商
     */
    private String brandOwner;

    /**
     * 简介
     */
    private String introduction;

    /**
     * 富文本
     */
    private String content;

    /**
     * 商品规格
     */
    private String specification;

    /**
     * 库存信息
     */
    private String inventory;
    @TableField(exist = false)
    private List<Map> inventorys;


    public List<Map> getInventorys() {
        if (inventory!=null){
            System.out.println(inventory);
          List<Map> aa=  JSON.parseArray(inventory, Map.class);

            return aa;

        }
        return inventorys;
    }

    /**
     * 其他参数
     */
    private String parameters;

    /**
     * 状态
     */
    private Integer status;


    private Integer newProducts;
    private Integer heatBuy;



}
